package com.boomcat.boomcat.dto;

import com.boomcat.boomcat.domain.Order;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderDto {
    private Long id;
    private Long expertId;
    //user's name online
    private String expertName;
    private String date;
    private Long gapSecond;

    public OrderDto(Order order) {
        id=order.getId();
        expertId=order.getExpertId();
        expertName= order.getExpertName();
        date=order.getDate();

        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime eTime = LocalDateTime.parse(date, formatter);

        if (now.isBefore(eTime)){
            Duration duration = Duration.between(now,eTime);
            gapSecond= duration.getSeconds();
        }else{
            gapSecond= -1L;
        }


    }

}
